/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.course.buy.record.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.course.buy.record.entity.TcourseBuyRecord;
import com.jeesite.modules.zx.course.buy.record.service.TcourseBuyRecordService;

/**
 * 用户课程购买记录Controller
 * @author zpp
 * @version 2020-02-16
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/course/buy/record/tcourseBuyRecord")
public class TcourseBuyRecordController extends BaseController {

	@Autowired
	private TcourseBuyRecordService tcourseBuyRecordService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TcourseBuyRecord get(String id, boolean isNewRecord) {
		return tcourseBuyRecordService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:course:buy:record:tcourseBuyRecord:view")
	@RequestMapping(value = {"list", ""})
	public String list(TcourseBuyRecord tcourseBuyRecord, Model model) {
		model.addAttribute("tcourseBuyRecord", tcourseBuyRecord);
		return "modules/zx/course/buy/record/tcourseBuyRecordList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:course:buy:record:tcourseBuyRecord:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TcourseBuyRecord> listData(TcourseBuyRecord tcourseBuyRecord, HttpServletRequest request, HttpServletResponse response) {
		tcourseBuyRecord.setPage(new Page<>(request, response));
		Page<TcourseBuyRecord> page = tcourseBuyRecordService.findPage(tcourseBuyRecord);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:course:buy:record:tcourseBuyRecord:view")
	@RequestMapping(value = "form")
	public String form(TcourseBuyRecord tcourseBuyRecord, Model model) {
		model.addAttribute("tcourseBuyRecord", tcourseBuyRecord);
		return "modules/zx/course/buy/record/tcourseBuyRecordForm";
	}

	/**
	 * 保存用户课程购买记录
	 */
	@RequiresPermissions("zx:course:buy:record:tcourseBuyRecord:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TcourseBuyRecord tcourseBuyRecord) {
		tcourseBuyRecordService.save(tcourseBuyRecord);
		return renderResult(Global.TRUE, text("保存用户课程购买记录成功！"));
	}
	
	/**
	 * 停用用户课程购买记录
	 */
	@RequiresPermissions("zx:course:buy:record:tcourseBuyRecord:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TcourseBuyRecord tcourseBuyRecord) {
		tcourseBuyRecord.setStatus(TcourseBuyRecord.STATUS_DISABLE);
		tcourseBuyRecordService.updateStatus(tcourseBuyRecord);
		return renderResult(Global.TRUE, text("停用用户课程购买记录成功"));
	}
	
	/**
	 * 启用用户课程购买记录
	 */
	@RequiresPermissions("zx:course:buy:record:tcourseBuyRecord:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TcourseBuyRecord tcourseBuyRecord) {
		tcourseBuyRecord.setStatus(TcourseBuyRecord.STATUS_NORMAL);
		tcourseBuyRecordService.updateStatus(tcourseBuyRecord);
		return renderResult(Global.TRUE, text("启用用户课程购买记录成功"));
	}
	
	/**
	 * 删除用户课程购买记录
	 */
	@RequiresPermissions("zx:course:buy:record:tcourseBuyRecord:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TcourseBuyRecord tcourseBuyRecord) {
		tcourseBuyRecordService.delete(tcourseBuyRecord);
		return renderResult(Global.TRUE, text("删除用户课程购买记录成功！"));
	}
	
}